package org.yzh.web.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.yzh.commons.util.PageResultDTO;
import org.yzh.commons.util.Ret;
import org.yzh.web.request.ElectronicFenceAddRequest;
import org.yzh.web.request.ElectronicFencePageSearchRequest;
import org.yzh.web.response.ElectronicFencePageSearchResponse;
import org.yzh.web.service.ElectronicFenceService;
import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 电子围栏表 前端控制器
 * </p>
 *
 * @author zgp
 * @since 2023-10-31
 */
@RestController
@Slf4j
@RequestMapping("/fence")
@Tag(name = "电子围栏接口")
public class ElectronicFenceController {

    @Resource
    private ElectronicFenceService electronicFenceService;

    @Operation(summary = "新增电子围栏")
    @PostMapping()
    public Ret save(@RequestBody ElectronicFenceAddRequest electronicFenceAddRequest) {
        electronicFenceService.save(electronicFenceAddRequest);
        return Ret.success("新增成功");
    }


    @Operation(summary = "编辑电子围栏")
    @PostMapping("/update")
    public Ret update(@RequestBody ElectronicFenceAddRequest electronicFenceAddRequest) {
        electronicFenceService.update(electronicFenceAddRequest);
        return Ret.success("编辑成功");
    }

    @Operation(summary = "删除电子围栏")
    @PostMapping("/remove/{ids}")
    public Ret remove(@PathVariable("ids") List<Integer> ids) {
        electronicFenceService.remove(ids);
        return Ret.success("删除成功");
    }
//    @Operation(summary = "查询电子围栏")
//    @PostMapping("/query")
//    public ResultPages query(@RequestBody ElectronicFencePageSearchRequest electronicFencePageSearchRequest) {
//
//        return electronicFenceService.select(electronicFencePageSearchRequest);
//    }

    @Operation(summary = "电子围栏分页")
    @PostMapping("/page")
    public Ret<PageResultDTO<ElectronicFencePageSearchResponse>> page(@RequestBody ElectronicFencePageSearchRequest request) {
        PageResultDTO<ElectronicFencePageSearchResponse> resultDTO = electronicFenceService.fencePage(request);
        return Ret.success(resultDTO);
    }
}

